<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['merchid'])){
		$params['merchid']=intval($_RQ['merchid']);
		$return['params']['merchid']=$_RQ['merchid'];
	}
	if(!empty($_RQ['goods_id'])){
		$return['params']['goods_id']=$_RQ['goods_id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$merchs=pdo_getslice('jy_goodserpfw_merch',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$list=array();
	if($merchs){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		if(!empty($_RQ['goodsid'])){
			$params2['goodsid']=intval($_RQ['goodsid']);
		}
		foreach($merchs as $item){
			$goods=pdo_getall('jy_goodserpfw_goods',$params2,array('title','id'));
			$merchtitle=pdo_getcolumn('jy_merch_user',array('id'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid']),'merchname');
			foreach($goods as $gv){
				$gv['merchtitle']=$merchtitle;
				$gv['code_num']=pdo_getsum('jy_goodserpfw_merchlog',array('type'=>1,'goods_id'=>$gv['id'],'merchid'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid']),'code_num');
				$list[]=$gv;
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'入库统计'),
		),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'delone'=>false,'list'=>array(
			array('name'=>'merchtitle','title'=>'经销商','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'code_num','title'=>'数量（盒）','type'=>'string'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>13,'title'=>'商品','name'=>'goodsid','action'=>'jy_goodserpfw/get_goods/'),
			array('type'=>'choose','width'=>13,'title'=>'经销商','name'=>'merchid','action'=>'jy_merch/get_merch/'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}